﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using CodeFirstDomain.IService;
using Framework.Infrastructure.IoC;
using Framework.Infrastructure;
using Framework.UnitOfWork;
using Microsoft.Practices.Unity;

namespace AppWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    [IocServiceBehavior]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class Service1 : IService1, IDisposable
    {
        int member = 0;

       IQueryService _queryService;
       public Service1(IQueryService queryService)
       {
           _queryService = queryService;
       }


        public string GetData(int value)
        {
            member++;
            var user = _queryService.GetUsers().FirstOrDefault();
            var user2 = IoCFactory.Resolve<IQueryService>().GetUsers().FirstOrDefault();
            return string.Format("You entered: {0} {1}", user.Name, member);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        #region IDisposable Members

        public void Dispose()
        {
            _queryService.Dispose();
            Utility.DisposeContainerExtensions();
        }

        #endregion
    }
}
